﻿using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AnesSystem.Util;
namespace AnesSystem.Controls
{
    /// <summary>
    /// ApplyOperationCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class ApplyOperationCtrl : UserControl
    {
        #region Variables
        private List<string> sList = new List<string>();
        private int year;
        private int month;
        private int day;
        #endregion


        #region Constructor
        public ApplyOperationCtrl()
        {
            InitializeComponent();
            this.DataContext = ApplyOperationCtrlViewModel.Instance;
            this.Loaded += ApplyOperationCtrl_Loaded;

        }

        private void ApplyOperationCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            ApplyOperationCtrlViewModel.Instance.init();
        }

        #endregion

        #region Properties

        #endregion

        #region 依赖属性

        public bool AgeEnable
        {
            get { return (bool)GetValue(AgeEnableProperty); }
            set { SetValue(AgeEnableProperty, value); }
        }

        // Using a DependencyProperty as the backing store for AgeEnable.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty AgeEnableProperty =
            DependencyProperty.Register("AgeEnable", typeof(bool), typeof(ApplyOperationCtrl), new PropertyMetadata(false));




        public bool DobEnable
        {
            get { return (bool)GetValue(DobEnableProperty); }
            set { SetValue(DobEnableProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DobEnable.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DobEnableProperty =
            DependencyProperty.Register("DobEnable", typeof(bool), typeof(ApplyOperationCtrl), new PropertyMetadata(false));


        #endregion

        #region Event


        #endregion

        #region PrivateMethods
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ApplyOperationCtrlViewModel.Instance.InsertPatient();
        }


        private void sssqsj_GotFocus(object sender, RoutedEventArgs e)
        {
            CusDatePickerWin cusDatePicker = new CusDatePickerWin();
            cusDatePicker.SelectedDateTime = DateTime.Now;
            cusDatePicker.ShowDialog();
            if (cusDatePicker.Result)
            {
                sssqsj.Text = cusDatePicker.SelectedDateTime.ToString(DateFormat.DATE_FORMAT_STR_YMDHM);//2005年11月5日
            }

        }

        private void jhss_GotFocus(object sender, RoutedEventArgs e)
        {
            CusDatePickerWin cusDatePicker = new CusDatePickerWin();
            cusDatePicker.SelectedDateTime = DateTime.Now;
            cusDatePicker.ShowDialog();
            if (cusDatePicker.Result)
            {
                jhss.Text = cusDatePicker.SelectedDateTime.ToString(DateFormat.DATE_FORMAT_STR_YMDHM);//2005年11月5日
            }
        }

        private void dob_GotFocus(object sender, RoutedEventArgs e)
        {
            CusDatePickerWin cusDatePicker = new CusDatePickerWin();
            cusDatePicker.SelectedDateTime = DateTime.Now;
            cusDatePicker.ShowDialog();
            if (cusDatePicker.Result)
            {
                dob.Text = cusDatePicker.SelectedDateTime.ToString(DateFormat.DATE_FORMAT_STR_YMD);//2005年11月5日
                ExtensionMethods.GetAgeByBirthday(cusDatePicker.SelectedDateTime, out year, out month, out day);
                int y = year;
                int m = month;
                int d = day;
                JudgeAge();
            }
        }
        #endregion

        #region Public/ProtectedMethods
        private void JudgeAge()
        {
            if (year > 0)
            {
                ApplyOperationCtrlViewModel.Instance.SelectedAgeUnit = "岁";
                ApplyOperationCtrlViewModel.Instance.Age = year.ToString();
            }
            else if (month > 0)
            {
                ApplyOperationCtrlViewModel.Instance.SelectedAgeUnit = "月";
                ApplyOperationCtrlViewModel.Instance.Age = month.ToString();
            }
            else
            {
                ApplyOperationCtrlViewModel.Instance.SelectedAgeUnit = "天";
                ApplyOperationCtrlViewModel.Instance.Age = day.ToString();
            }
        }

        #endregion

        #region EventHandlers


        #endregion

        private void Nianling_Click(object sender, RoutedEventArgs e)
        {
            string commond = (sender as RadioButton).Tag.ToString();
            switch (commond)
            {
                case "nianling1":
                    {
                        AgeEnable = true;
                        DobEnable = false;
                    }
                    break;
                case "nianling2":
                    {
                        AgeEnable = false;
                        DobEnable = true;
                    }
                    break;
                case "nianling3":
                    {
                        AgeEnable = false;
                        DobEnable = false;
                    }
                    break;
            }
        }
    }
}
